<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="cn">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.0.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.0.0" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="categories">
<meta property="og:url" content="http://yoursite.com/categories/index.html">
<meta property="og:site_name" content="hill&#39;s blog">
<meta property="og:locale" content="cn">
<meta property="article:published_time" content="2017-07-10T08:36:26.000Z">
<meta property="article:modified_time" content="2021-02-25T04:04:48.836Z">
<meta property="article:author" content="heyaojia">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/categories/"/>





  <title>游戏开发相关/游戏开发寻路总结 | hill's blog</title>
  








<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="cn">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">hill's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/03/30/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%9B%B8%E5%85%B3/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E5%AF%BB%E8%B7%AF%E6%80%BB%E7%BB%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="heyaojia">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="hill's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">游戏开发相关/游戏开发寻路总结</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2021-03-30T11:19:39+08:00">2021-03-30</time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="游戏开发中寻路学习归纳"><a href="#游戏开发中寻路学习归纳" class="headerlink" title="游戏开发中寻路学习归纳"></a>游戏开发中寻路学习归纳</h4><hr>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">###目录：</span></span><br><span class="line">	1.什么是寻路</span><br><span class="line">	2.最基本的寻路</span><br><span class="line">	3.游戏研发中常用的寻路算法归纳</span><br><span class="line">	4.Github上有什么高star的寻路算法</span><br></pre></td></tr></table></figure>

<h5 id="1-寻路"><a href="#1-寻路" class="headerlink" title="1. 寻路"></a>1. 寻路</h5><p>​        寻路顾名思义，就是寻找道路，寻找道路又可以分为寻找正确的道路（不要求快）和寻找一条快速的道路（不一定是最优）。寻路算法是SLG、ARPG游戏中常用功能，该功能的作用是，释放玩家双手，减少繁杂的找寻NPC、地点、任务目标的过程，提高玩家游戏熟悉程度，游戏玩法节奏控制及其效率。虽然在项目中不是我负责寻路模块，但是作为一个游戏研发人员，这是必备技能。</p>
<a id="more"></a>

<h5 id="2-基本的寻路"><a href="#2-基本的寻路" class="headerlink" title="2. 基本的寻路"></a>2. 基本的寻路</h5><p>​    最基本的寻路，叫广度优先算法，起始位置附近相邻的节点全部检索一次，直到找到最终坐标</p>
<h5 id="3-常用的寻路算法-学习链接"><a href="#3-常用的寻路算法-学习链接" class="headerlink" title="3. 常用的寻路算法    学习链接"></a>3. 常用的寻路算法    <a href="https://www.jianshu.com/p/8b3cdca55dc0[" target="_blank" rel="noopener">学习链接</a></h5><ol>
<li><p><strong><em>Dijkstra 算法</em></strong></p>
<p><img src="/images/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E5%AF%BB%E8%B7%AF%E6%80%BB%E7%BB%93/image-20210331143731734.png" alt="image-20210331143731734"></p>
</li>
</ol>
<ul>
<li><p>题目 -&gt; 如上图，求顶点1到顶点6的最短距离</p>
<p><strong><em>Dijkstra算法解如下:</em></strong></p>
<ol>
<li><p>按照所有顶点到开始顶点一的权重放到队列dist中,无法连通的就用无穷大表示</p>
<p><img src="/images/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E5%AF%BB%E8%B7%AF%E6%80%BB%E7%BB%93/image-20210331144300086.png" alt="image-20210331144300086"></p>
</li>
<li><p>遍历出最小的那个顶点（首次为起始顶点）</p>
<p>First :<strong><em>MIN</em></strong>  = node[1] = 0</p>
<p>N :<strong><em>MIN</em></strong>  = node[n] = mini</p>
</li>
<li><p>将该顶点放到done list中，遍历他的around顶点，找出最小的那个顶点（这里是顶点<code>node[2]</code> = 1）</p>
</li>
<li><p>将该顶点也放到done list，再次遍历他的around顶点,发现<code>node[1][2]</code> + <code>node[2][3]</code> &lt; dist[3], 为这条边松弛。</p>
</li>
<li><p>重复234点</p>
</li>
</ol>
<p><strong><em>DIjikstra算法</em></strong>代码：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Dljikstra start</span></span><br><span class="line">  待补充</span><br></pre></td></tr></table></figure>

<p><strong><em>DIjikstra算法</em></strong>总结：</p>
<ol>
<li>比广度优先效率高</li>
</ol>
</li>
</ul>
<ol start="2">
<li><p>没有目的的搜索，要全部节点看一遍。好比不知道中终点在哪里，只知道计算好所有的利弊，才去走，每次都要遍历最小。</p>
</li>
<li><p><strong><em>贪心寻路算法</em></strong></p>
<p>贪心算法一般是一个问题拆成n个小问题，每个小问题都取最优解。再寻路中，贪心寻路算法为，取起始节点的附近节点计算曼哈顿距离，选取最小值，不断循环这一操作，直到找到终点</p>
<p><strong><em>贪心寻路算法</em></strong>总结：</p>
<ol>
<li>贪心法求出解不一定是最优解，因为不一定每一步最优解就是结果最优解。</li>
</ol>
</li>
<li><p><strong><em>A星算法</em></strong> </p>
<ul>
<li><p><strong><em>A星算法</em></strong> 集合了<strong><em>Dlijikstra算法</em></strong>和<strong><em>贪心寻路算法</em></strong>的优点</p>
<p><strong><em>A星算法</em></strong>解法是：</p>
<p><strong><em>Dlijikstra</em></strong>步骤，但是在选取最小值的时候，采用<a href="http://www.go60.top/dsj/66.html" target="_blank" rel="noopener">曼哈顿距离</a>计算，而不是用权重</p>
</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// A* start</span></span><br><span class="line">   <span class="keyword">var</span> 待补充</span><br></pre></td></tr></table></figure>


</li>
</ol>
<h5 id="4-算法补充"><a href="#4-算法补充" class="headerlink" title="4. 算法补充"></a>4. 算法补充</h5><ol>
<li><p><strong><em>B星算法</em></strong> </p>
<p><a href="https://blog.csdn.net/qq_43461641/article/details/100711157" target="_blank" rel="noopener">https://blog.csdn.net/qq_43461641/article/details/100711157</a></p>
</li>
<li><p><strong><em>待补充</em></strong></p>
</li>
</ol>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/03/27/%E6%88%91%E7%9A%84%E9%A1%B9%E7%9B%AE/GO%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E5%BA%93/" rel="next" title="我的项目/GO实现日志库">
                <i class="fa fa-chevron-left"></i> 我的项目/GO实现日志库
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/04/01/Nosql/Redis-%E5%9F%BA%E7%A1%80/" rel="prev" title="Nosql/Redis-基础">
                Nosql/Redis-基础 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">heyaojia</p>
              <p class="site-description motion-element" itemprop="description">游戏行业的一枚小鲜肉</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="git@gitee.com:hillcool/hillcool.git" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-gitee"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#游戏开发中寻路学习归纳"><span class="nav-number">1.</span> <span class="nav-text">游戏开发中寻路学习归纳</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-寻路"><span class="nav-number">1.1.</span> <span class="nav-text">1. 寻路</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-基本的寻路"><span class="nav-number">1.2.</span> <span class="nav-text">2. 基本的寻路</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-常用的寻路算法-学习链接"><span class="nav-number">1.3.</span> <span class="nav-text">3. 常用的寻路算法    学习链接</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-算法补充"><span class="nav-number">1.4.</span> <span class="nav-text">4. 算法补充</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">heyaojia</span>

  

  
</div>









        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.0"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
